<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>jsonp</h1>
    <button id="btn">发送jsonp请求</button>
    <script>
    function callback (){
        console.log('跨域成功');
    }
    let btn = document.querySelector('#btn')
    //5.清空初始值
    let script = null
    //1.点击点击创建一个script元素节点,,通过元素节点来跨域
    btn.onclick = function(){
        //2.创建一个script元素节点
        script = document.createElement('script')
        //3.给节点添加src属性,用来跨域
        script.src = 'http://127.0.0.1:1010/get?userid=001&cb=callback'
        //4.把节点挂上去
        document.body.appendChild(script)
    }
    </script>
</body>
</html>